package jp.co.piratealliance.pirateAllianceWeb.web.action.goods;

import java.util.ArrayList;
import java.util.List;

import jp.co.piratealliance.pirateAllianceWeb.common.base.BaseAction;
import jp.co.piratealliance.pirateAllianceWeb.dto.com.AreaInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.goods.GoodsInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.service.goods.GoodsService;


/**
 * copyright pirate alliance team 2014
 *
 * @author lunxing
 */

public class GetAreaListAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private GoodsService goodsService;

	private List<AreaInfoDto> areaList;

	private String language_id;

	private int level;

	private String name;

	public String getAreaInfoList()
	{
		if (this.level > 0) {
			this.areaList = this.goodsService.getAreaListByLevel(this.language_id, this.level);
		} else {
			this.areaList = new ArrayList<AreaInfoDto>();

			List<String> area_ids = null;

			if (null != this.name && !"".equals(this.name)) {
				area_ids = this.goodsService.getAreaIDListByName(this.name);
			}

			if (null != area_ids) {
				for (int i = 0; i < area_ids.size(); i++) {
					String area_id = area_ids.get(i);

					List<GoodsInfoDto> goodsList = this.goodsService.getGoodsList(0, area_id, this.language_id, 0, 1);

					if (null == goodsList || goodsList.size() == 0) {
						continue;
					}

					AreaInfoDto areaInfoDto = this.goodsService.getAreaByAreaIDAndLanguageId(area_id, this.language_id);

					this.areaList.add(areaInfoDto);
				}
			}
		}

		return SUCCESS;
	}

	/**
	 * @return the goodsService
	 */
	public GoodsService getGoodsService() {
		return goodsService;
	}

	/**
	 * @param goodsService the goodsService to set
	 */
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	/**
	 * @return the areaList
	 */
	public List<AreaInfoDto> getAreaList() {
		return areaList;
	}

	/**
	 * @param areaList the areaList to set
	 */
	public void setAreaList(List<AreaInfoDto> areaList) {
		this.areaList = areaList;
	}

	/**
	 * @return the language_id
	 */
	public String getLanguage_id() {
		return language_id;
	}

	/**
	 * @param language_id the language_id to set
	 */
	public void setLanguage_id(String language_id) {
		this.language_id = language_id;
	}

	/**
	 * @return the level
	 */
	public int getLevel() {
		return level;
	}

	/**
	 * @param level the level to set
	 */
	public void setLevel(int level) {
		this.level = level;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

}
